import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import axios from 'axios';
import qs from 'qs';

// 配置 Axios 基础 URL
axios.defaults.baseURL = 'http://localhost:8080/elm/';

const app = createApp(App);

// 将 Axios 和 qs 挂载到全局属性上
app.config.globalProperties.$axios = axios;
app.config.globalProperties.$qs = qs;

// Session Storage
app.config.globalProperties.$getSessionStorage = function (key) {
  return JSON.parse(sessionStorage.getItem(key));
};
app.config.globalProperties.$setSessionStorage = function (key, value) {
  sessionStorage.setItem(key, JSON.stringify(value));
};
app.config.globalProperties.$removeSessionStorage = function (key) {
  sessionStorage.removeItem(key);
};

// Local Storage
app.config.globalProperties.$getLocalStorage = function (key) {
  return JSON.parse(localStorage.getItem(key));
};
app.config.globalProperties.$setLocalStorage = function (key, value) {
  localStorage.setItem(key, JSON.stringify(value));
};
app.config.globalProperties.$removeLocalStorage = function (key) {
  localStorage.removeItem(key);
};

app.use(router);
app.mount('#app');
